package android.slc.box.core.launcher;

import android.slc.box.core.scope.StageScope;
import android.slc.box.core.virtual_android.Bundle;
import cn.hutool.core.util.ArrayUtil;
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.Scope;
import de.saxsys.mvvmfx.ViewModel;
import javafx.stage.Stage;
import javafx.stage.Window;

public interface EmbeddedWindowLauncher extends WindowLauncher<Window> {

    @Override
    default <ViewType extends FxmlView<? extends ViewModelType>, ViewModelType extends ViewModel> void launcherWindow(Window targetWindow, Class<ViewType> viewClass, Bundle bundle, Scope... scopes) {
        /*if (getWindow() instanceof EmbeddedWindow) {
            EmbeddedWindowScope stageScope = EmbeddedWindowScope.newInstance((EmbeddedWindow) getWindow(), (EmbeddedWindow) targetWindow);
            Scope[] scopeArray = ArrayUtil.append(scopes, stageScope);
            launcherWindow(targetWindow, createView(viewClass, bundle, scopeArray));
        } else if (getWindow() instanceof Stage) {
            launcherWindow((Stage) targetWindow, viewClass, bundle, new StageLauncherConfig() {
            }, scopes);
        }*/
        if (getWindow() instanceof Stage) {
            launcherWindow((Stage) targetWindow, viewClass, bundle, new StageLauncherConfig() {
            }, scopes);
        }
    }

    /**
     * 启动窗口
     *
     * @param targetWindow
     * @param viewClass
     * @param scopes
     * @param <ViewType>
     * @param <ViewModelType>
     */
    default <ViewType extends FxmlView<? extends ViewModelType>, ViewModelType extends ViewModel> void launcherWindow(Stage targetWindow,
                                                                                                                      Class<ViewType> viewClass,
                                                                                                                      StageLauncherConfig stageLauncherConfig,
                                                                                                                      Scope... scopes) {
        this.launcherWindow(targetWindow, viewClass, null, stageLauncherConfig, scopes);
    }

    /**
     * 启动窗口
     *
     * @param targetWindow
     * @param viewClass
     * @param bundle
     * @param scopes
     * @param <ViewType>
     * @param <ViewModelType>
     */
    default <ViewType extends FxmlView<? extends ViewModelType>, ViewModelType extends ViewModel> void launcherWindow(Stage targetWindow,
                                                                                                                      Class<ViewType> viewClass,
                                                                                                                      Bundle bundle,
                                                                                                                      StageLauncherConfig stageLauncherConfig,
                                                                                                                      Scope... scopes) {
        StageScope stageScope = StageScope.newInstance(null, targetWindow, stageLauncherConfig);
        Scope[] scopeArray = ArrayUtil.append(scopes, stageScope);
        launcherWindow(targetWindow, createView(viewClass, bundle, scopeArray));
    }

}
